#ifndef IDENTIFICACAO_H
#define IDENTIFICACAO_H

#include <QObject>

#include <cstdlib>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <matrix.h>
#include "pid.h"

struct Ciclos{
    std::vector<double> TimePoints;
    std::vector<double> PVPoints;
    std::vector<double> CVPoints;
};

class identificacao : public QObject
{
Q_OBJECT
private:
    identificacao();
    ~identificacao();
    static  identificacao* instance;

    std::vector<Ciclos> faixas;
    std::vector<double> TimePoints;
    std::vector<double> PVPoints;
    std::vector<double> CVPoints;

    int tempoIdent;
    double timePast;
    double timeNow;
    double tempoAux;
    double factor;
    int cycle;
    bool identifying;

    void endOfCycle();
    void refreshCycle(int cycle);
    void calcFODT();
    int findIndex(std::vector<double> pvVector, bool crescente, double lim);

    std::vector<double> mypow(std::vector<double> x, int expoente);
    double mysum(std::vector<double> x);
    std::vector<double> prodInterno(std::vector<double> x,std::vector<double> y);
    std::vector<double> gerarY(vvector c,std::vector<double> x);
    std::vector<double> mdf(std::vector<double> f, double h);
    fvector ajpoly(std::vector<double> x, std::vector<double> y, int ordem);
    void printVector(std::vector<double> x);

public:
    static identificacao *getInstance();
    bool running;
    double ganho;
    double constTempo;
    double tempoMorto;
    double fatorIncont;

public slots:
    void calcStep();
    void setTime(int);
    void cancel();

signals:
    void changeSetPoint(double);
    void endIdentify();
};

#endif // IDENTIFICACAO_H
